﻿using System;
using System.Collections.Generic;
using System.IO;

namespace Platformer_Example.Controller.Data
{
    public class MapSummary
    {
        public static List<MapSummary> GetMapInfo()
        {
            List<MapSummary> maps = new List<MapSummary>();

            string[] files = Directory.GetFiles("Content/Map", "*.info", SearchOption.AllDirectories);
            foreach (var file in files)
            {
                maps.Add(new MapSummary(file));
            }

            return maps;
        }

        public MapSummary(string file)
        {
            MapName = Path.GetFileNameWithoutExtension(file);

            using (var SR = new StreamReader(file))
            {
                Teams = Convert.ToInt32(SR.ReadLine());
                PlayersPerTeam = Convert.ToInt32(SR.ReadLine());
            }    
        }

        public MapSummary(string mapName, int teams, int playersPerTeam)
        {
            MapName = mapName;
            Teams = teams;
            PlayersPerTeam = playersPerTeam;
        }

        public override string ToString()
        {
            return string.Format("{0} map, {1} teams of {2} players", MapName, Teams, PlayersPerTeam);
        }

        public string MapName { get; private set; }
        public int PlayersPerTeam { get; private set; }
        public int Teams { get; private set; }

        public int TotalPlayers
        {
            get { return PlayersPerTeam*Teams; }
        }
    }
}